import random
from commom import enemy_prefixes, enemy_suffixes
from skill import Skill
from prettytable import PrettyTable


class Hero:
    def __init__(self, nickname, health, attack, mana, armor, critical, skills):
        self.nickname = nickname
        self.health = health
        self.attack = attack
        self.mana = mana
        self.armor = armor
        self.critical = critical
        self.skills = skills

    def clone(self):
        return Hero(self.nickname, self.health, self.attack, self.mana, self.armor, self.critical, self.skills)

    def __str__(self):
        tb = PrettyTable(['英雄信息', '数值'])
        tb.add_row(['昵称', self.nickname])
        tb.add_row(['生命值', self.health])
        tb.add_row(['攻击力', self.attack])
        tb.add_row(['护甲值', self.armor])
        tb.add_row(['魔法值', self.mana])
        tb.add_row(['暴击率', self.critical])
        for i in range(len(self.skills)):
            tb.add_row([f'技能{i + 1}', self.skills[i]])
        return tb.__str__()

    @classmethod
    def random_hero(cls, nickname):
        nickname = nickname
        chance = 1.1
        health = random.randint(80, 120)
        chance += (100 - health) / 100
        attack = int(random.randint(15, 30) * chance)
        chance += (20 - attack) / 75
        mana = int(random.randint(8, 15) * chance)
        chance += (10 - mana) / 35
        armor = int(random.randint(5, 15) * chance)
        chance += (10 - armor) / 50
        critical = int(random.randint(5, 15) * chance)
        skills = []
        if int((chance / 15) * 500) >= random.randint(1, 100):
            skills.append(Skill.random_skill())
        return cls(nickname, health, attack, mana, armor, critical, skills)

    @classmethod
    def random_enemy(cls, current_level):
        nickname = random.choice(enemy_prefixes) + random.choice(enemy_suffixes)
        chance = 0.8 + current_level * 0.1
        health = int(random.randint(50, 100) * chance)
        chance += (70 - health) / 100
        attack = int(random.randint(10, 20) * chance)
        chance += (15 - attack) / 50
        mana = int(random.randint(8, 15) * chance)
        chance += (10 - mana) / 35
        armor = int(random.randint(3, 10) * chance)
        chance += (4 - armor) / 7
        critical = int(random.randint(5, 15) * chance)
        skills = []
        for i in range(int(current_level / 3)):
            n = len(skills)
            if int(chance * 20 - n) >= random.randint(1, 100):
                skills.append(Skill.random_skill())

        return cls(nickname, health, attack, mana, armor, critical, skills)


if __name__ == '__main__':
    print(Hero.random_enemy(3))
